/*!
   \file

   © 2011 Mark W. Gabby II

   This file is part of the Avion engine.

   The Avion engine is free software: you can redistribute it and/or modify it under the terms of
   the GNU General Public License as published by the Free Software Foundation, either version 3 of
   the License, or (at your option) any later version.

   The Avion engine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
   without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
   the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along with the Avion Engine.
   If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include <vector>

#include "Util/typedefs.hpp"
#include "Util/CoordPair.hpp"
#include "Util/MemMappedFile.hpp"
#include "Math/AABB.hpp"

class AvionModel
{
public:
   AvionModel();

   bool Load( const char * Filepath );

   bool LoadFromFIFFObject();

   bool IsModelLoaded();

   void DeAllocate();

   uint32_t GetTriangleCount()
   {
      return triangleCount;
   }
   uint8_t GetBufferCount()
   {
      return bufferCount;
   }

   const char * GetTextureMapName()
   {
      return textureMapName.c_str();
   }
   const char * GetNormalMapName()
   {
      return normalMapName.c_str();
   }

   float * GetVertexData()
   {
      return vertexData;
   }
   uint32_t GetVertexSizeBytes()
   {
      return vertexSizeBytes;
   }

   float * GetNormalData()
   {
      return normalData;
   }
   uint32_t GetNormalSizeBytes()
   {
      return normalSizeBytes;
   };

   float * GetVcolorData()
   {
      return vColorData;
   }
   uint32_t GetVcolorSizeBytes()
   {
      return vColorSizeBytes;
   };

   float * GetSpecClrData()
   {
      return specColorData;
   }
   uint32_t GetSpecColorSizeBytes()
   {
      return specColorSizeBytes;
   };

   uint8_t * GetSpecPowers()
   {
      return specPowers;
   }
   uint32_t GetSpecPowerSizeBytes()
   {
      return specPowerSizeBytes;
   };

   float * GetTextureCoords()
   {
      return textureCoords;
   }
   uint32_t GetTextureCoordsSizeBytes()
   {
      return textureCoordsSizeBytes;
   };

   uint32_t * GetTriangleIndices()
   {
      return triangleIndices;
   }
   uint32_t GetTriangleIndicesSizeBytes()
   {
      return triangleIndicesSizeBytes;
   };

   uint32_t GetBoneIndicesSize()
   {
      return ( uint32_t )boneIndices.size();
   }

   char * GetBoneIndices( int index )
   {
      return boneIndices[index];
   }
   uint32_t GetBoneIndicesSizeBytes( int index )
   {
      return boneIndicesSizeBytes[index];
   };

   char * GetBones()
   {
      return bones;
   }
   uint32_t GetBonesSizeBytes()
   {
      return bonesSizeBytes;
   }
   const std::string & GetName()
   {
      return name;
   }

   AABB<> GetBoundingBox()
   {
      return boundingBox;
   }

   ~AvionModel();
private:

   std::string name;
   MemMappedFile file;

   bool usingMemory;

   uint32_t triangleCount;
   uint32_t vertexCount;
   uint8_t bufferCount;

   std::string textureMapName;
   std::string normalMapName;

   // Buffers
   float * vertexData;
   uint32_t vertexSizeBytes;
   float * normalData;
   uint32_t normalSizeBytes;
   float * vColorData;
   uint32_t vColorSizeBytes;
   float * specColorData;
   uint32_t specColorSizeBytes;
   uint8_t * specPowers;
   uint32_t specPowerSizeBytes;
   float * textureCoords;
   uint32_t textureCoordsSizeBytes;
   uint32_t * triangleIndices;
   uint32_t triangleIndicesSizeBytes;
   std::vector<char *> boneIndices;
   std::vector<uint32_t> boneIndicesSizeBytes;
   char * bones;
   uint32_t bonesSizeBytes;

   AABB<> boundingBox;
};
